package com.jackson.framespringbootnacos.controller;

/*
 * Author: JacksonCoder
 * FileName: TestController
 * Version: 1.0.0
 * Date: 2025/4/19
 */

import com.jackson.framespringbootnacos.config.AppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class TestController {

    @Value("${app.name:}")  // 给默认值，避免 value 为 null
    private String appName;

    @Value("${app.desc:}")
    private String desc;

    @Autowired
    private AppConfig appConfig;

    /**
     * http://localhost:9087/config
     * @return
     */
    @GetMapping("/config")
    public Map<String, String> getConfig() {
        Map<String, String> map = new HashMap<>();
        // 1. 只放非空 key
        map.put("app.name", appName);
        map.put("app.desc", desc);
        return map;
    }

    /**
     * http://localhost:9087/AppConfig
     * @return
     */
    @GetMapping("/AppConfig")
    public Map<String, String> getForAppConfig(){
        Map<String,String> map = new HashMap<>();
        map.put("app.name",appConfig.getAppName());
        map.put("app.desc",appConfig.getDesc());
        return map;
    }

}
